import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		hasLogin: false, //用户是否登录
		token: '', //用户数据
		//第三方tabBar相关
		active: 'collection',
		animate: 'zoomIn',
		tabbars: [{
				name: 'collection',
				text: '收藏',
				icon: '/static/icon/collection.svg',
				iconActive: '/static/icon/collection-selected.svg',
				// dot: true,
				path: '/pages/tabBar/collection/collection'
			},
			{
				name: 'category',
				text: '分类',
				icon: '/static/icon/ranking.svg',
				iconActive: '/static/icon/ranking-selected.svg',
				path: '/pages/tabBar/category/category'
			},
			{
				name: 'ranking',
				text: '排行榜',
				icon: '/static/icon/collection.svg',
				iconActive: '/static/icon/collection-selected.svg',
				path: '/pages/tabBar/ranking/ranking'
			},
			{
				name: 'person',
				text: '个人',
				icon: '/static/icon/person.svg',
				iconActive: '/static/icon/person-selected.svg',
				path: '/pages/tabBar/person/person'
			}
		]
	},
	getters: {
		active: state => state.active,
		animate: state => state.animate,
		tabbars: state => state.tabbars
	},
	//mutations定义同步操作的方法
	mutations: {
		// 登录
		login(state, token) {
			//登录状态为已登录
			state.hasLogin = true
			state.token = token
			//储存用户数据到本地
			uni.setStorage({
				key: 'token',
				data: token,
			});
			console.log('登陆成功')
		},

		// 退出登录
		logout(state) {
			//登录状态为未登录
			state.hasLogin = false
			state.token = ''
			//删除本地储存
			uni.removeSavedFile({
				key: 'token',
			})
			console.log('退出登录')
		},
		//tabBar
		SET_ACTIVE(state, data) {
			state.active = data
		},
		SET_TABBARS(state, data) {
			state.tabbars = data
		}
	},
	actions: {

	}
})
export default store
